package demo.jms.converter;

import java.io.Serializable;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.ObjectMessage;
import javax.jms.Session;

import org.springframework.jms.support.converter.MessageConversionException;
import org.springframework.jms.support.converter.MessageConverter;

/**
 * 邮件消息转换器
 * 
 * @author JSC
 *
 */
public class EmailMessageConverter implements MessageConverter {

	@Override
	public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
		System.out.println("[调用了EmailMessageConverter的toMessage方法]");
		return session.createObjectMessage((Serializable) object);
	}

	@Override
	public Object fromMessage(Message message) throws JMSException, MessageConversionException {
		System.out.println("[调用了EmailMessageConverter的fromMessage方法]");
		System.setProperty("org.apache.activemq.SERIALIZABLE_PACKAGES", "*");// 指定可反序列化的包
		ObjectMessage objMessage = (ObjectMessage) message;
		return objMessage.getObject();
	}

}
